<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class Applystreet extends CI_Controller {
	var $eData = '';
	function __construct() {
		parent::__construct ();
		$this->thor->loginstate ();
	}
	
	function index() {
		$this->load->library('pagination');
		
		$eSearch = trim($this->input->get('search'));
		$ePage = (int)$this->input->get('num');
		
		
		if($eSearch != '') $this->db->like('name', $eSearch); 
		$this->db->where('type', 1 ); 
		$eConfig['total_rows'] = $this->db->count_all_results('apply');
		
		$this->db->order_by('applytime', 'desc');
		$this->db->order_by('id', 'desc');
		if($eSearch != '') $this->db->like('name', $eSearch);
		$this->db->where('type', 1 ); 
		$this->eData['applyList'] = $this->db->get('apply', 25, $ePage)->result();

		$eConfig['per_page'] = 25;
		$eConfig['num_links'] = 5;
		$eConfig['base_url'] = '?1=1';
		$this->pagination->initialize($eConfig); 
		
		$this->eData['eSearch']      = $eSearch;
		$this->eData['eCount']       = $eConfig['total_rows'];
		
		$this->load->view ( 'mang/applystreet',$this->eData );
	}
	
	function status(){
		
		$status = (int)$this->input->get('status');
		$eData = array(
			'status'=>$status,
			'audittime'=>time()
		);
		$this->db->where('id',(int)$this->input->get('id'));
		$this->db->update('apply', $eData);
		//如果审核通过则将他设置为街道主任
		if($status == 2){
			$this->db->select('applymember,applyuname,code');
			$this->db->where('id',(int)$this->input->get('id'));
			$apply = $this->db->get('apply')->row_array();
			$data = array(
				'manager'=>$apply['applymember'],
				'mangname'=>$apply['applyuname']
			);
			$this->db->where('id',$apply['code']);
			$this->db->update('street', $data);
		}
		
		
		redirect('mang/applystreet');
	}
	
	function delete(){
		$eID = (int)$this->input->get('id');
		if($eID == 0) $eCheckID = $this->input->post('checkID');
		else $eCheckID[] = $eID;
		
		$this->db->where_in('id', $eCheckID);
		$this->db->delete('apply');
		redirect('mang/applystreet');
	}

}